"use strict";
/* Controllers */
app.controller("costOverviewController", ['$scope', '$location', '$rootScope', '$routeParams', 'costOverviewService', function ($scope, $location, $rootScope, $routeParams, costOverviewService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};

    if (!vm.p.dt) {
        vm.p.dt = getNowFormatDate(-1);
    }
    vm.p.oa = $GLOBAL_USER;

    var errorFn = function (result) {
        alert(result);
    };

    $scope.loadCostOverview = function (t) {
        var vm = $scope.vm;
        $scope.listCostOverview();
    };

    $scope.listCostOverview = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var param = vm.p;
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) {
                return;
            }
            $("#dt").text(data.dt);
            $("#ownerId").text(data.ownerId);
            $("#taskScore").text(data.taskScore);
            $("#storageScore").text(data.storageScore);
            $('#detail_table').bootstrapTable('load', data.billingOwnerEntityList);
        };
        costOverviewService.listCostOverview(param, procFn, errorFn);
    };

    $scope.initializeController = function () {
        $scope.vm.result.ms = '';

        var $resultTable2 = $('#detail_table');
        $resultTable2.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.listCostOverview();
    };

    $scope.initializeController();

}]);



/* Services */
app.service('costOverviewService', ['ajaxService', function (ajaxService) {

    this.listCostOverview = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/costOverview/getCostOverview.do", successFunction, errorFunction);
    };

}]);

/**
 * 数据的国际化格式化方式，三个数据用逗号分隔 如123456转换成123,456
 */
function internationalNumberFormatter(value) {
    value += '';
    var x = value.split('.');
    var x1 = x[0];
    var x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

function toPencent(num, row, index) {
    if (num == null) {
        return "-";
    }
    return (parseFloat(num) * 100).toFixed(2) + '%'
}